﻿using Runoi.StockQuantBrain.Entity;

namespace Runoi.StockQuantBrain
{
    /// <summary>
    /// 交易执行模块
    /// </summary>
    public class TradeExecutor
    {
        private readonly Account _account;
        /// <summary>
        /// 
        /// </summary>
        /// <param name="account"></param>
        public TradeExecutor(Account account)
        {
            _account = account;
        }

        /// <summary>
        /// 执行买入订单
        /// </summary>
        /// <param name="price">买入价格</param>
        /// <param name="quantity">买入数量</param>
        public async Task ExecuteBuyOrder(decimal price, int quantity)
        {
            var totalPrice = price * quantity; // 计算总金额
            if (!_account.TryWithdraw(totalPrice)) // 检查可用资金是否充足
                return;

            // 模拟异步下单过程（实际应用中应替换为真实的下单接口）
            await Task.Delay(1000); // 模拟异步操作
            LogHelper.LogTrade("513010", price, quantity, isBuy: true); // 记录交易日志
        }
    }
}
